using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace ConsoleApplication2.Models.Mapping
{
    public class AL_PatAllergyMap : EntityTypeConfiguration<AL_PatAllergy>
    {
        public AL_PatAllergyMap()
        {
            // Primary Key
            this.HasKey(t => t.ID);

            // Properties
            this.Property(t => t.UID)
                .IsRequired()
                .HasMaxLength(20);

            this.Property(t => t.ChangeReason)
                .HasMaxLength(50);

            // Table & Column Mappings
            this.ToTable("AL_PatAllergy");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.Allergy).HasColumnName("Allergy");
            this.Property(t => t.PatientIID).HasColumnName("PatientIID");
            this.Property(t => t.OnsetDate).HasColumnName("OnsetDate");
            this.Property(t => t.Status).HasColumnName("Status");
            this.Property(t => t.comment).HasColumnName("comment");
            this.Property(t => t.Severity).HasColumnName("Severity");
            this.Property(t => t.Reaction).HasColumnName("Reaction");
            this.Property(t => t.Type).HasColumnName("Type");
            this.Property(t => t.UID).HasColumnName("UID");
            this.Property(t => t.ChangeReason).HasColumnName("ChangeReason");
            this.Property(t => t.ExpiryDate).HasColumnName("ExpiryDate");

            // Relationships
            this.HasOptional(t => t.AL_allergy)
                .WithMany(t => t.AL_PatAllergy)
                .HasForeignKey(d => d.Allergy);
            this.HasOptional(t => t.AL_Reaction)
                .WithMany(t => t.AL_PatAllergy)
                .HasForeignKey(d => d.Reaction);
            this.HasOptional(t => t.AL_Severity)
                .WithMany(t => t.AL_PatAllergy)
                .HasForeignKey(d => d.Severity);
            this.HasOptional(t => t.Al_Status)
                .WithMany(t => t.AL_PatAllergy)
                .HasForeignKey(d => d.Status);
            this.HasOptional(t => t.AL_Type)
                .WithMany(t => t.AL_PatAllergy)
                .HasForeignKey(d => d.Type);

        }
    }
}
